<?php

declare(strict_types=1);

namespace App\Model;

use App\Model\Permission\User;
use Hyperf\DbConnection\Model\Model;

/**
 * @property int $id 
 * @property int $school_id 
 * @property int $department_id 
 * @property int $teacher_id 
 * @property string $name 
 * @property int $member_count 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property int $creator_id 
 * @property-read null|User $teacher 
 * @property-read null|School $school 
 * @property-read null|Department $department 
 * @property-read null|\Hyperf\Database\Model\Collection|User[] $teachers 
 */
class Classroom extends Model
{
    use Traits\HasCreator;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'classroom';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'school_id', 'department_id', 'teacher_id', 'name', 'member_count', 'created_at', 'updated_at', 'creator_id'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'school_id' => 'integer', 'department_id' => 'integer', 'teacher_id' => 'integer', 'member_count' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'creator_id' => 'integer'];

    public function teacher(){
        return $this->belongsTo(User::class,'teacher_id');
    }
    public function school(){
        return $this->belongsTo(School::class);
    }
    public function department(){
        return $this->belongsTo(Department::class);
    }

    public function teachers(){
        return $this->belongsToMany(User::class,'classroom_teacher');
    }
}
